<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>es5 原型寄生式继承方案</title>
</head>
<body>

  <script>
    const obj = {
      name: '张三',
      age: 18,
      friends: ['李四', '王五']
    }

    // 原型式继承
    function createObj(o) {
      function F() {}
      F.prototype = o
      return new F()
    }

    // 寄生式继承
    function createObj2(o, name, age, height, address) {
      const clone = createObj(o)
      clone.name = name
      clone.age = age
      clone.height = height
      clone.sex = sex
      return clone
    }

    // 创建另外一个对象, 这个对象可以继承自obj
    // var info1 = createObj(obj)  
    // info1.height = 1.88
    // info1.address = "广州市"

    // var info2 = createObj(obj)  
    // info1.height = 1.88
    // info1.address = "广州市"

    // var info3 = createObj(obj)  
    // info1.height = 1.88
    // info1.address = "广州市"

    // 创建一系列对象
    var info3 = createInfo(obj, "james", 35, 2.08, "克利夫兰市")
    
  </script>
  
</body>
</html>